<template>
  <el-table :data="list" stripe style="width: 100%">
    <el-table-column prop="projectName" label="产品名称"></el-table-column>
    <el-table-column prop="status" label="支付状态"></el-table-column>
    <el-table-column prop="payType" label="支付类型"></el-table-column>
    <el-table-column prop="totalPrice" label="总价"></el-table-column>
    <el-table-column prop="creationTime" label="下单时间" width="150"></el-table-column>
    <el-table-column fixed="right" label="操作" width="100">
      <template slot-scope="scope">
        <el-button @click="handleDetail(scope.row)" type="text" size="small">查看</el-button>
        <el-button @click="handleDelete(scope.row)" type="text" size="small">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { getOrderList, deleteOrder } from "@/api/order";
export default {
  name: "orderTable",
  data() {
    return {
      list: null,
      total: 0,
      listQuery: {
        page: 1,
        limit: 10
      }
    };
  },
  created() {
    getOrderList(this.listQuery).then(response => {
      this.list = response.data.items;
      this.total = response.data.total;
    });
  },
  methods: {
    getOrders() {
      getOrderList(this.listQuery).then(response => {
        this.list = response.data.items;
        this.total = response.data.total;
      });
    },
    handleDelete(row) {
      this.$confirm("确定删除订单？", "提示", {
        confirmButtonTest: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        const loading = this.$loading({
          text: "正在删除订单"
        });
        deleteOrder(row.id)
          .then(response => {
            loading.close();
            this.$notify({
              title: response.success ? "成功" : "失败",
              message: response.message,
              type: response.success ? "success" : "error",
              duration: 2000
            });
          })
          .catch(error => {
            loading.close();
          });
      });
    }
  }
};
</script>
